//
//  HMMineViewController.m
//  G05爱鲜蜂
//
//  Created by 源 何 on 16/10/15.
//  Copyright © 2016年 何源. All rights reserved.
//

#import "HMMineViewController.h"
#import "HMuserInfoView.h"
#import "HMSettingViewController.h"
#import "HMmyMessageView.h"
#import "HMmyLoveTableView.h"
#import "HMAdviceViewController.h"
#import "HMCustomServoceViewController.h"
#import "HMSaveViewController.h"
#import "HMGetGoodsAdressTableViewController.h"
#import <UMSocialCore/UMSocialCore.h>
#import "UMSocialUIManager.h"
#import "HMMyOrderViewController.h"
@interface HMMineViewController ()

@end

@implementation HMMineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
 
    [self setUpUI];

}
-(void)setUpUI
{
    
    //设置导航栏隐藏
    self.navigationController.navigationBarHidden = YES;
 
    //用户信息view
    HMuserInfoView *userInfoView = [[HMuserInfoView alloc] init];
    [self.view addSubview:userInfoView];
    [userInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.equalTo(self.view);
        make.width.equalTo(self.view);
        make.height.equalTo(self.view).multipliedBy(0.22);
    }];
    
    userInfoView.settingBtnClick = ^{
        //跳转
        HMSettingViewController *settingVC = [[HMSettingViewController alloc] init];
        settingVC.hidesBottomBarWhenPushed = YES;

        
        [self.navigationController pushViewController:settingVC animated:YES];
    };
    //用户订单等view
    HMmyMessageView *myMessageView = [HMmyMessageView loadMyMessageView];
    [self.view addSubview:myMessageView];
    [myMessageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(userInfoView.mas_bottom);
        make.trailing.leading.equalTo(self.view);
        make.height.equalTo(self.view).multipliedBy(0.11);
    }];
    myMessageView.btnClick = ^(BtnClickEvent btn){
        if(btn == BtnClickEventOrder){
            HMMyOrderViewController *orderVC = [[HMMyOrderViewController alloc] init];
            orderVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:orderVC animated:YES];
        }
        else if (btn == BtnClickEventQuan){
            
        }else{
            
        }
    };

    //myLoveTableView
    HMmyLoveTableView *myLoveTableView = [[HMmyLoveTableView alloc] initWithFrame:CGRectMake(0,self.view.frame.size.height - (self.view.frame.size.height *(1-0.22-0.11)),self.view.frame.size.width , self.view.frame.size.height *(1-0.11-0.22)) style:UITableViewStyleGrouped];
    [self.view addSubview:myLoveTableView];
    
    myLoveTableView.jumpToBlock = ^(JumpToVC jump){
        if(jump == JumpToVCGetGoods){
             HMGetGoodsAdressTableViewController *getGoodAdressTableView = [[HMGetGoodsAdressTableViewController alloc] init];
            getGoodAdressTableView.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:getGoodAdressTableView animated:YES];
        }
        else if (jump == JumpToVCMyShop){
             HMSaveViewController *saveVC = [[HMSaveViewController alloc] init];
            saveVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:saveVC animated:YES];
        }
        else if (jump == JumpToVCShare){
            
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"分享到" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
            UIAlertAction *alertActionFriend = [UIAlertAction actionWithTitle:@"微信好友" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                NSLog(@"微信好友");

            }];
            [alertController addAction:alertActionFriend];

            UIAlertAction *alertActionQuan = [UIAlertAction actionWithTitle:@"微信朋友圈" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                NSLog(@"跳转微信朋友圈");
            }];
            [alertController addAction:alertActionQuan];

            UIAlertAction *alertActionSina = [UIAlertAction actionWithTitle:@"新浪微博" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                [self  shareTextToSina];
                
                
            }];
            [alertController addAction:alertActionSina];

            UIAlertAction *alertActionQQ= [UIAlertAction actionWithTitle:@"QQ空间" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                NSLog(@"QQ空间");

            }];
            [alertController addAction:alertActionQQ];

            UIAlertAction *alertActionChanel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            [alertController addAction:alertActionChanel];
            
            dispatch_async(dispatch_get_main_queue(), ^{
               [self presentViewController:alertController animated:YES completion:nil];
            });
            

         }
        else if (jump == JumpToVCHelp){
            HMCustomServoceViewController *customServoceVC = [[HMCustomServoceViewController alloc] init];
            customServoceVC.hidesBottomBarWhenPushed = YES;

            [self.navigationController pushViewController:customServoceVC animated:YES];
        }else{
            HMAdviceViewController *adviceVC = [[HMAdviceViewController alloc] init];
            adviceVC.hidesBottomBarWhenPushed = YES;

            [self.navigationController pushViewController:adviceVC animated:YES];
        }
    };
}
//分享文本
- (void)shareTextToSina
{
    NSString *text = @"";
    
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    
    messageObject.text = text;
    
    [[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_Sina messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        NSString *message = nil;
        if (!error) {
            message = [NSString stringWithFormat:@"分享成功"];
        } else {
            message = [NSString stringWithFormat:@"失败原因Code: %d\n",(int)error.code];
            
        }
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"share"
                                                        message:message
                                                       delegate:nil
                                              cancelButtonTitle:NSLocalizedString(@"确定", nil)
                                              otherButtonTitles:nil];
        [alert show];
    }];
}
@end
